var checkCategoryForPost = function(categoryId, option) {        
    var data = {
        category_id: categoryId
    };
    var postId = location.pathname.match(/\/post_id\/(.*)/);
    if (postId != null) {
        postId = postId[1];
    }
    $.post('/admin/ajax/check-category', data, function(r) {            
        r = JSON.parse(r);
        if (r.result == 'error' && r.post_id !== postId) {                    
            $.jGrowl(r.message);                    
            option.attr('disabled', 'disabled');
            option.css({color: 'red'});                    
        }
    })
}

$('select[name="category"]').live('change', function() {
    var option = $('select[name="category"] option:selected'); 
    checkCategoryForPost(option.val(), option);                     
}) 

